//
//  OrderFooterView.m
//  FD
//
//  Created by Yasin on 2018/10/16.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//
//  0，支付，4评价，其他都是再来一单
//上:44*3+10  中:50*8  下:60
// ((44*3+10) + 50*8 + 60)

#import "OrderFooterView.h"
//view
#import "OrderFooterTopCouponFreightView.h" //上
#import "OrderFooterDownView.h"             //下
#import "OrderFooterCenterTableViewCell.h"
//#import "OrderFooterCenterTableViewCell.h" //xib cell

//proxy
#import "OrderFooterCenterTableViewProxy.h" //代理

@interface OrderFooterView()
//上中下三部分
//上 优惠券、配送费 已经优惠 合计:
@property (nonatomic, strong) OrderFooterTopCouponFreightView *upView;

/**中*/
@property (nonatomic, strong) UITableView *tableView;

//中 tableView===========
/**下*/
@property (nonatomic, strong) OrderFooterDownView *downView;
/**tableViewProxye*/
@property (nonatomic, strong) OrderFooterCenterTableViewProxy *proxy;

@end

@implementation OrderFooterView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    self.tableView.frame = self.bounds;
    [self addSubview:self.tableView];
    
    self.tableView.tableHeaderView = self.upView;
    self.tableView.tableFooterView = self.downView;
}

#pragma mark - getter
- (OrderFooterTopCouponFreightView *)upView {
    if (!_upView) {
        _upView = [[OrderFooterTopCouponFreightView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44*3 + 10)];
        //44 + 44 + 44 + 10分割线
//        _upView.backgroundColor = [UIColor redColor];
    }
    return _upView;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.scrollEnabled = NO; //✅
        
        //代理
        _tableView.delegate = self.proxy;
        _tableView.dataSource = self.proxy;
        
        //注册cell
        [_tableView registerNib:[UINib nibWithNibName:@"OrderFooterCenterTableViewCell" bundle:nil] forCellReuseIdentifier:@"OrderFooterCenterTableViewCell"];
        
        //取消分割线
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    }
    return _tableView;
}
- (OrderFooterCenterTableViewProxy *)proxy {
    if (!_proxy) {
        _proxy = [[OrderFooterCenterTableViewProxy alloc] init];
    }
    return _proxy;
}


- (OrderFooterDownView *)downView {
    if (!_downView) {
        _downView = [[OrderFooterDownView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 60)];
        
        //block回调
        FDWeakSelf;
        _downView.clickLeftBtnBlock = ^{
            if ([weakSelf.delegate respondsToSelector:@selector(clickOrderFooterViewActionType:)]) {
                [weakSelf.delegate clickOrderFooterViewActionType:(OrderFooterViewActionLeft)];
            }
        };
        
        _downView.clickRightBtnBlock = ^{
            if ([weakSelf.delegate respondsToSelector:@selector(clickOrderFooterViewActionType:)]) {
                [weakSelf.delegate clickOrderFooterViewActionType:(OrderFooterViewActionTypeRight)];
            }
        };
    }
    return _downView;
}


#pragma mark - 接口 上
/** 0.优惠券 、 1.配送费 、 2.已经优惠  、 3.合计: */
- (void)updateTopCouponFreightViewWithCoupon:(NSNumber *)coupon freight:(NSNumber *)freight alreadyCoupon:(CGFloat)alreadyCoupon sum:(NSNumber *)sum {
    
    [self.upView setDataWithCoupon:coupon freight:freight alreadCoupon:alreadyCoupon sum:sum];
}


#pragma mark - 接口 中 ✅
/**给tableView 赋值*/
- (void)updateCenterTableViewDataArray:(NSArray *)dataArr {
    self.proxy.dataArr = dataArr;
    [self.tableView reloadData]; //记得刷新
}

#pragma mark - 接口 下 ✅
/**1-23*/
- (void)updateRightBtnTitleWithStatus:(NSNumber *)status payType:(NSNumber *)paytype deliveryType:(NSNumber *)deliveryType {
    
    [self.downView orderFooterDownViewUpdateRightBtnTitleWithStatus:status payType:paytype deliveryType:deliveryType];
}



/**11-26根据状态更新右边按钮的文字 0，支付，4评价，其他都是再来一单 */
//- (void)updateRightBtnTitleWithStatus:(NSNumber *)status payType:(NSNumber *)paytype{
//    [self.downView orderFooterDownViewUpdateRightBtnTitleWithStatus:status payType:paytype];
//}

#pragma mark - 假数据
//- (NSArray *)fakeData {
//    NSArray *fakeArr = @[@{@"firstStr":@"订单信息",@"secondStr":@""},
//                         @{@"firstStr":@"姓名:",@"secondStr":@"刘德华"},
//                         @{@"firstStr":@"联系电话:",@"secondStr":@"1008611"},
//                         @{@"firstStr":@"地址:",@"secondStr":@"3 Kenley ava"},
//                         @{@"firstStr":@"备注:",@"secondStr":@""},
//                         @{@"firstStr":@"支付方式:",@"secondStr":@"在线支付"},
//                         @{@"firstStr":@"订单号:",@"secondStr":@"201901080000005"},
//                         @{@"firstStr":@"新增积分:",@"secondStr":@"8.5"},
//                         ];
//
//    //转模型
//    NSMutableArray *tempArrM = @[].mutableCopy;
//    for (NSDictionary *dic  in fakeArr) {
//        OrderFooterCenterTableViewCellModel *model = [OrderFooterCenterTableViewCellModel mj_objectWithKeyValues:dic];
//        [tempArrM addObject:model];
//    }
//
//    return [tempArrM copy];
//}

@end
